<?php

namespace App\Http\Controllers\Web\Seller;

use App\ConstDir\ErrorConst;
use App\Http\Controllers\Web\BaseController;
use App\Repository\Repositories\Interfaces\BrandAuditRepository;
use Illuminate\Http\Request;
use App\Repository\Models\BrandAudit;

/**
 * 品牌管理控制器
 *
 * @package App\Http\Controllers\Backend
 */
class BrandAuditController extends BaseController
{
    /**
     * @var BrandAuditRepository
     */
    protected $brand;

    protected $shop_id;

    public function __construct(BrandAuditRepository $brand)
    {
        parent::__construct();
        $this->brand = $brand;
        $this->shop_id = array_get($this->user, 'shop_id');

//        //用户只能操作自身所属数据
        $this->brand->scopeQuery(function ($query) {
            return $query->where('shop_id',$this->shop_id);

        });
    }

    public function index()
    {
        $brands = $this->brand->paginate($this->perPage);

        return $this->success(ErrorConst::SUCCESS_CODE_MSG, $brands, true);
    }


    public function show($id)
    {

        $brand_info = $this->brand->with('shop')->find($id);

        return $this->success(ErrorConst::SUCCESS_CODE, $brand_info);
    }



    public function store(Request $request)
    {

        $data = $request->all();
        $data['shop_id']=$this->shop_id;

        $ret = $this->brand->create($data);
        if($ret){
            return $this->success(ErrorConst::SUCCESS_CODE, $ret);
        }else{
            return $this->error(ErrorConst::FAILED_CODE);
        }

//        return $this->noDataReturn($ret ? true : false);
    }


}
